# -*- coding: utf-8 -*-
"""
支持子类化
这个实现允许子类化,子类可以继承单例基类的功能,并添加自己的初始化逻辑
"""
import threading


class BaseSingleton(object):
    _instance = None
    _lock = threading.Lock()

    def __new__(cls, *args, **kwargs):
        with cls._lock:
            if cls._instance is None:
                cls._instance = super(BaseSingleton, cls).__new__(cls)
        return cls._instance


class Concretesingleton(BaseSingleton):
    def __init__(self, param1, param2):
        self.param1 = param1
        self.param2 = param2
